home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Modules / timemodule.c < prev    next >
C/C++ Source or Header  |  1999-04-26  |  16KB  |  671 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* Time module */
  33.  
  34. #include "Python.h"
  35.  
  36. #ifdef HAVE_SELECT
  37. #include "mymath.h"
  38. #endif
  39.  
  40. #ifdef macintosh
  41. #include <time.h>
  42. #else
  43. #include <sys/types.h>
  44. #endif
  45.  
  46. #ifdef _AMIGA
  47. #include <proto/dos.h>
  48. #endif
  49.  
  50. #ifdef QUICKWIN
  51. #include <io.h>
  52. #endif
  53.  
  54. #ifdef HAVE_UNISTD_H
  55. #include <unistd.h>
  56. #endif
  57.  
  58. #ifdef HAVE_SELECT
  59. #include "myselect.h"
  60. #else
  61. #include "mytime.h"
  62. #endif
  63.  
  64. #ifdef HAVE_FTIME
  65. #include <sys/timeb.h>
  66. #if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
  67. extern int ftime();
  68. #endif /* MS_WINDOWS */
  69. #endif /* HAVE_FTIME */
  70.  
  71. #if defined(__WATCOMC__) && !defined(__QNX__)
  72. #include <i86.h>
  73. #else
  74. #ifdef MS_WINDOWS
  75. #include <windows.h>
  76. #ifdef MS_WIN16
  77. /* These overrides not needed for Win32 */
  78. #define timezone _timezone
  79. #define tzname _tzname
  80. #define daylight _daylight
  81. #define altzone _altzone
  82. #endif /* MS_WIN16 */
  83. #endif /* MS_WINDOWS */
  84. #endif /* !__WATCOMC__ || __QNX__ */
  85.  
  86. #ifdef MS_WIN32
  87. /* Win32 has better clock replacement */
  88. #include <largeint.h>
  89. #undef HAVE_CLOCK /* We have our own version down below */
  90. #endif /* MS_WIN32 */
  91.  
  92. #if defined(PYOS_OS2)
  93. #define  INCL_DOS
  94. #define  INCL_DOSERRORS
  95. #define  INCL_NOPMAPI
  96. #include <os2.h>
  97. #endif
  98.  
  99. #if defined(PYCC_VACPP)
  100. #include <time.h>
  101. #define timezone _timezone
  102. #endif
  103.  
  104. /* Forward declarations */
  105. static int floatsleep Py_PROTO((double));
  106. static double floattime Py_PROTO(());
  107.  
  108. #include "protos/timemodule_protos.h"
  109.  
  110. #ifdef macintosh
  111. /* Our own timezone. We have enough information to deduce whether
  112. ** DST is on currently, but unfortunately we cannot put it to good
  113. ** use because we don't know the rules (and that is needed to have
  114. ** localtime() return correct tm_isdst values for times other than
  115. ** the current time. So, we cop out and only tell the user the current
  116. ** timezone.
  117. */
  118. static long timezone;
  119.  
  120. static void 
  121. initmactimezone()
  122. {
  123.     MachineLocation    loc;
  124.     long        delta;
  125.  
  126.     ReadLocation(&loc);
  127.     
  128.     if (loc.latitude == 0 && loc.longitude == 0 && loc.u.gmtDelta == 0)
  129.         return;
  130.     
  131.     delta = loc.u.gmtDelta & 0x00FFFFFF;
  132.     
  133.     if (delta & 0x00800000)
  134.         delta |= 0xFF000000;
  135.     
  136.     timezone = -delta;
  137. }
  138. #endif /* macintosh */
  139.  
  140.  
  141. static PyObject *
  142. time_time(self, args)
  143.     PyObject *self;
  144.     PyObject *args;
  145. {
  146.     double secs;
  147.     if (!PyArg_NoArgs(args))
  148.         return NULL;
  149.     secs = floattime();
  150.     if (secs == 0.0) {
  151.         PyErr_SetFromErrno(PyExc_IOError);
  152.         return NULL;
  153.     }
  154.     return PyFloat_FromDouble(secs);
  155. }
  156.  
  157. #ifdef HAVE_CLOCK
  158.  
  159. #ifndef CLOCKS_PER_SEC
  160. #ifdef CLK_TCK
  161. #define CLOCKS_PER_SEC CLK_TCK
  162. #else
  163. #define CLOCKS_PER_SEC 1000000
  164. #endif
  165. #endif
  166.  
  167. static PyObject *
  168. time_clock(self, args)
  169.     PyObject *self;
  170.     PyObject *args;
  171. {
  172.     if (!PyArg_NoArgs(args))
  173.         return NULL;
  174.     return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
  175. }
  176. #endif /* HAVE_CLOCK */
  177.  
  178. #ifdef MS_WIN32
  179. /* Due to Mark Hammond */
  180. static PyObject *
  181. time_clock(self, args)
  182.     PyObject *self;
  183.     PyObject *args;
  184. {
  185.     static LARGE_INTEGER ctrStart;
  186.     static LARGE_INTEGER divisor = {0,0};
  187.     LARGE_INTEGER now, diff, rem;
  188.  
  189.     if (!PyArg_NoArgs(args))
  190.         return NULL;
  191.  
  192.     if (LargeIntegerEqualToZero(divisor)) {
  193.         QueryPerformanceCounter(&ctrStart);
  194.         if (!QueryPerformanceFrequency(&divisor) || 
  195.             LargeIntegerEqualToZero(divisor)) {
  196.                 /* Unlikely to happen - 
  197.                    this works on all intel machines at least! 
  198.                    Revert to clock() */
  199.             return PyFloat_FromDouble(clock());
  200.         }
  201.     }
  202.     QueryPerformanceCounter(&now);
  203.     diff = LargeIntegerSubtract(now, ctrStart);
  204.     diff = LargeIntegerDivide(diff, divisor, &rem);
  205.     /* XXX - we assume both divide results fit in 32 bits.  This is
  206.        true on Intels.  First person who can afford a machine that 
  207.        doesnt deserves to fix it :-)
  208.     */
  209.     return PyFloat_FromDouble((double)diff.LowPart + 
  210.                       ((double)rem.LowPart / (double)divisor.LowPart));
  211. }
  212. #define HAVE_CLOCK /* So it gets included in the methods */
  213. #endif /* MS_WIN32 */
  214.  
  215. static PyObject *
  216. time_sleep(self, args)
  217.     PyObject *self;
  218.     PyObject *args;
  219. {
  220.     double secs;
  221.     if (!PyArg_Parse(args, "d", &secs))
  222.         return NULL;
  223.     if (floatsleep(secs) != 0)
  224.         return NULL;
  225.     Py_INCREF(Py_None);
  226.     return Py_None;
  227. }
  228.  
  229. static PyObject *
  230. time_convert(when, function)
  231.     time_t when;
  232.     struct tm * (*function) Py_PROTO((const time_t *));
  233. {
  234.     struct tm *p;
  235.     errno = 0;
  236.     p = function(&when);
  237.     if (p == NULL) {
  238. #ifdef EINVAL
  239.         if (errno == 0)
  240.             errno = EINVAL;
  241. #endif
  242.         return PyErr_SetFromErrno(PyExc_IOError);
  243.     }
  244.     return Py_BuildValue("(iiiiiiiii)",
  245.                  p->tm_year + 1900,
  246.                  p->tm_mon + 1,        /* Want January == 1 */
  247.                  p->tm_mday,
  248.                  p->tm_hour,
  249.                  p->tm_min,
  250.                  p->tm_sec,
  251.                  (p->tm_wday + 6) % 7, /* Want Monday == 0 */
  252.                  p->tm_yday + 1,       /* Want January, 1 == 1 */
  253.                  p->tm_isdst);
  254. }
  255.  
  256. static PyObject *
  257. time_gmtime(self, args)
  258.     PyObject *self;
  259.     PyObject *args;
  260. {
  261.     double when;
  262.     if (!PyArg_Parse(args, "d", &when))
  263.         return NULL;
  264.     return time_convert((time_t)when, gmtime);
  265. }
  266.  
  267. static PyObject *
  268. time_localtime(self, args)
  269.     PyObject *self;
  270.     PyObject *args;
  271. {
  272.     double when;
  273.     if (!PyArg_Parse(args, "d", &when))
  274.         return NULL;
  275.     return time_convert((time_t)when, localtime);
  276. }
  277.  
  278. static int
  279. gettmarg(args, p)
  280.     PyObject *args;
  281.     struct tm *p;
  282. {
  283.     if (!PyArg_Parse(args, "(iiiiiiiii)",
  284.              &p->tm_year,
  285.              &p->tm_mon,
  286.              &p->tm_mday,
  287.              &p->tm_hour,
  288.              &p->tm_min,
  289.              &p->tm_sec,
  290.              &p->tm_wday,
  291.              &p->tm_yday,
  292.              &p->tm_isdst))
  293.         return 0;
  294.     if (p->tm_year >= 1900)
  295.         p->tm_year -= 1900;
  296.     p->tm_mon--;
  297.     p->tm_wday = (p->tm_wday + 1) % 7;
  298.     p->tm_yday--;
  299.     return 1;
  300. }
  301.  
  302. #ifdef HAVE_STRFTIME
  303. static PyObject *
  304. time_strftime(self, args)
  305.     PyObject *self;
  306.     PyObject *args;
  307. {
  308.     struct tm buf;
  309.     const char *fmt;
  310.     char *outbuf = 0;
  311.     int i;
  312.  
  313.     if (!PyArg_ParseTuple(args, "s(iiiiiiiii)",
  314.                   &fmt,
  315.                   &(buf.tm_year),
  316.                   &(buf.tm_mon),
  317.                   &(buf.tm_mday),
  318.                   &(buf.tm_hour),
  319.                   &(buf.tm_min),
  320.                   &(buf.tm_sec),
  321.                   &(buf.tm_wday),
  322.                   &(buf.tm_yday),
  323.                   &(buf.tm_isdst)))
  324.         return NULL;
  325.     if (buf.tm_year >= 1900)
  326.         buf.tm_year -= 1900;
  327.     buf.tm_mon--;
  328.     buf.tm_wday = (buf.tm_wday + 1) % 7;
  329.     buf.tm_yday--;
  330. #ifdef HAVE_MKTIME
  331.     /* This call is only there to adjust the numbers to be within
  332.        bounds.  When we don't have mktime(), we say the caller is
  333.        responsible for that... */
  334.     (void) mktime(&buf);
  335. #endif
  336.     /* I hate these functions that presume you know how big the output
  337.      * will be ahead of time...
  338.      */
  339.     for (i = 1024 ; i <= 8192 ; i += 1024) {
  340.         outbuf = malloc(i);
  341.         if (outbuf == NULL) {
  342.             return PyErr_NoMemory();
  343.         }
  344.         if (strftime(outbuf, i-1, fmt, &buf) != 0) {
  345.             PyObject *ret;
  346.             ret = PyString_FromString(outbuf);
  347.             free(outbuf);
  348.             return ret;
  349.         }
  350.         free(outbuf);
  351.     }
  352.     PyErr_SetString(PyExc_ValueError,
  353.             "bad strftime format or result too big");
  354.     return NULL;
  355. }
  356. #endif /* HAVE_STRFTIME */
  357.  
  358. static PyObject *
  359. time_asctime(self, args)
  360.     PyObject *self;
  361.     PyObject *args;
  362. {
  363.     struct tm buf;
  364.     char *p;
  365.     if (!gettmarg(args, &buf))
  366.         return NULL;
  367.     p = asctime(&buf);
  368.     if (p[24] == '\n')
  369.         p[24] = '\0';
  370.     return PyString_FromString(p);
  371. }
  372.  
  373. static PyObject *
  374. time_ctime(self, args)
  375.     PyObject *self;
  376.     PyObject *args;
  377. {
  378.     double dt;
  379.     time_t tt;
  380.     char *p;
  381.     if (!PyArg_Parse(args, "d", &dt))
  382.         return NULL;
  383.     tt = (time_t)dt;
  384.     p = ctime(&tt);
  385.     if (p == NULL) {
  386.         PyErr_SetString(PyExc_ValueError, "unconvertible time");
  387.         return NULL;
  388.     }
  389.     if (p[24] == '\n')
  390.         p[24] = '\0';
  391.     return PyString_FromString(p);
  392. }
  393.  
  394. #ifdef HAVE_MKTIME
  395. static PyObject *
  396. time_mktime(self, args)
  397.     PyObject *self;
  398.     PyObject *args;
  399. {
  400.     struct tm buf;
  401.     time_t tt;
  402.     tt = time(&tt);
  403.     buf = *localtime(&tt);
  404.     if (!gettmarg(args, &buf))
  405.         return NULL;
  406.     tt = mktime(&buf);
  407.     if (tt == (time_t)(-1)) {
  408.         PyErr_SetString(PyExc_OverflowError,
  409.                                 "mktime argument out of range");
  410.         return NULL;
  411.     }
  412.     return PyFloat_FromDouble((double)tt);
  413. }
  414. #endif /* HAVE_MKTIME */
  415.  
  416. static PyMethodDef time_methods[] = {
  417.     {"time",    time_time},
  418. #ifdef HAVE_CLOCK
  419.     {"clock",    time_clock},
  420. #endif
  421.     {"sleep",    time_sleep},
  422.     {"gmtime",    time_gmtime},
  423.     {"localtime",    time_localtime},
  424.     {"asctime",    time_asctime},
  425.     {"ctime",    time_ctime},
  426. #ifdef HAVE_MKTIME
  427.     {"mktime",    time_mktime},
  428. #endif
  429. #ifdef HAVE_STRFTIME
  430.     {"strftime",    time_strftime, 1},
  431. #endif
  432.     {NULL,        NULL}        /* sentinel */
  433. };
  434.  
  435. static void
  436. ins(d, name, v)
  437.     PyObject *d;
  438.     char *name;
  439.     PyObject *v;
  440. {
  441.     if (v == NULL)
  442.         Py_FatalError("Can't initialize time module -- NULL value");
  443.     if (PyDict_SetItemString(d, name, v) != 0)
  444.         Py_FatalError(
  445.         "Can't initialize time module -- PyDict_SetItemString failed");
  446.     Py_DECREF(v);
  447. }
  448.  
  449. void
  450. inittime()
  451. {
  452.     PyObject *m, *d;
  453.     m = Py_InitModule("time", time_methods);
  454.     d = PyModule_GetDict(m);
  455. #ifdef HAVE_TZNAME
  456.     tzset();
  457.     ins(d, "timezone", PyInt_FromLong((long)timezone));
  458. #ifdef HAVE_ALTZONE
  459.     ins(d, "altzone", PyInt_FromLong((long)altzone));
  460. #else
  461.     ins(d, "altzone", PyInt_FromLong((long)timezone-3600));
  462. #endif
  463.     ins(d, "daylight", PyInt_FromLong((long)daylight));
  464.     ins(d, "tzname", Py_BuildValue("(zz)", tzname[0], tzname[1]));
  465. #else /* !HAVE_TZNAME */
  466. #if HAVE_TM_ZONE
  467.     {
  468. #define YEAR ((time_t)((365 * 24 + 6) * 3600))
  469.         time_t t;
  470.         struct tm *p;
  471.         long winterzone, summerzone;
  472.         char wintername[10], summername[10];
  473.         /* XXX This won't work on the southern hemisphere.
  474.           XXX Anybody got a better idea? */
  475.         t = (time((time_t *)0) / YEAR) * YEAR;
  476.         p = localtime(&t);
  477.         winterzone = -p->tm_gmtoff;
  478.         strncpy(wintername, p->tm_zone ? p->tm_zone : "   ", 9);
  479.         wintername[9] = '\0';
  480.         t += YEAR/2;
  481.         p = localtime(&t);
  482.         summerzone = -p->tm_gmtoff;
  483.         strncpy(summername, p->tm_zone ? p->tm_zone : "   ", 9);
  484.         summername[9] = '\0';
  485.         ins(d, "timezone", PyInt_FromLong(winterzone));
  486.         ins(d, "altzone", PyInt_FromLong(summerzone));
  487.         ins(d, "daylight",
  488.                     PyInt_FromLong((long)(winterzone != summerzone)));
  489.         ins(d, "tzname",
  490.                     Py_BuildValue("(zz)", wintername, summername));
  491.     }
  492. #else
  493. #ifdef macintosh
  494.     /* The only thing we can obtain is the current timezone
  495.     ** (and whether dst is currently _active_, but that is not what
  496.     ** we're looking for:-( )
  497.     */
  498.     initmactimezone();
  499.     ins(d, "timezone", PyInt_FromLong(timezone));
  500.     ins(d, "altzone", PyInt_FromLong(timezone));
  501.     ins(d, "daylight", PyInt_FromLong((long)0));
  502.     ins(d, "tzname", Py_BuildValue("(zz)", "", ""));
  503. #endif /* macintosh */
  504. #endif /* HAVE_TM_ZONE */
  505. #endif /* !HAVE_TZNAME */
  506.     if (PyErr_Occurred())
  507.         Py_FatalError("Can't initialize time module");
  508. }
  509.  
  510.  
  511. /* Implement floattime() for various platforms */
  512.  
  513. static double
  514. floattime()
  515. {
  516.     /* There are three ways to get the time:
  517.       (1) gettimeofday() -- resolution in microseconds
  518.       (2) ftime() -- resolution in milliseconds
  519.       (3) time() -- resolution in seconds
  520.       In all cases the return value is a float in seconds.
  521.       Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
  522.       fail, so we fall back on ftime() or time().
  523.       Note: clock resolution does not imply clock accuracy! */
  524. #ifdef HAVE_GETTIMEOFDAY
  525.     {
  526.         struct timeval t;
  527. #ifdef GETTIMEOFDAY_NO_TZ
  528.         if (gettimeofday(&t) == 0)
  529.             return (double)t.tv_sec + t.tv_usec*0.000001;
  530. #else /* !GETTIMEOFDAY_NO_TZ */
  531.         if (gettimeofday(&t, (struct timezone *)NULL) == 0)
  532.             return (double)t.tv_sec + t.tv_usec*0.000001;
  533. #endif /* !GETTIMEOFDAY_NO_TZ */
  534.     }
  535. #endif /* !HAVE_GETTIMEOFDAY */
  536.     {
  537. #ifdef HAVE_FTIME
  538.         struct timeb t;
  539.         ftime(&t);
  540.         return (double)t.time + (double)t.millitm * (double)0.001;
  541. #else /* !HAVE_FTIME */
  542.         time_t secs;
  543.         time(&secs);
  544.         return (double)secs;
  545. #endif /* !HAVE_FTIME */
  546.     }
  547. }
  548.  
  549.  
  550. /* Implement floatsleep() for various platforms.
  551.    When interrupted (or when another error occurs), return -1 and
  552.    set an exception; else return 0. */
  553.  
  554. static int
  555. #ifdef MPW
  556. floatsleep(double secs)
  557. #else
  558.     floatsleep(secs)
  559.     double secs;
  560. #endif /* MPW */
  561. {
  562. /* XXX Should test for MS_WIN32 first! */
  563. #ifdef HAVE_SELECT
  564.     struct timeval t;
  565.     double frac;
  566.  
  567. #if defined (AMITCP) || defined(INET225)
  568.     /* select needs [bsd]socket.library with TCP stacks -- I.J. */
  569.     if(!checksocketlib())
  570.     {
  571.         /* no bsdsocket.library-- use dos/Delay() */
  572.         PyErr_Clear();
  573.         Delay((long)(secs*50));        /* XXX Can't interrupt this sleep */
  574.         return 0;
  575.     }
  576. #endif
  577.  
  578.     frac = fmod(secs, 1.0);
  579.     secs = floor(secs);
  580.     t.tv_sec = (long)secs;
  581.     t.tv_usec = (long)(frac*1000000.0);
  582.     Py_BEGIN_ALLOW_THREADS
  583.     if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
  584.         Py_BLOCK_THREADS
  585.         PyErr_SetFromErrno(PyExc_IOError);
  586.         return -1;
  587.     }
  588.     Py_END_ALLOW_THREADS
  589. #else /* !HAVE_SELECT */
  590. #ifdef macintosh
  591. #define MacTicks    (* (long *)0x16A)
  592.     long deadline;
  593.     deadline = MacTicks + (long)(secs * 60.0);
  594.     while (MacTicks < deadline) {
  595.         /* XXX Should call some yielding function here */
  596.         if (PyErr_CheckSignals())
  597.             return -1;
  598.     }
  599. #else /* !macintosh */
  600. #if defined(__WATCOMC__) && !defined(__QNX__)
  601.     /* XXX Can't interrupt this sleep */
  602.     Py_BEGIN_ALLOW_THREADS
  603.     delay((int)(secs * 1000 + 0.5));  /* delay() uses milliseconds */
  604.     Py_END_ALLOW_THREADS
  605. #else /* !__WATCOMC__ || __QNX__ */
  606. #ifdef MSDOS
  607.     struct timeb t1, t2;
  608.     double frac;
  609.     extern double fmod Py_PROTO((double, double));
  610.     extern double floor Py_PROTO((double));
  611.     if (secs <= 0.0)
  612.         return;
  613.     frac = fmod(secs, 1.0);
  614.     secs = floor(secs);
  615.     ftime(&t1);
  616.     t2.time = t1.time + (int)secs;
  617.     t2.millitm = t1.millitm + (int)(frac*1000.0);
  618.     while (t2.millitm >= 1000) {
  619.         t2.time++;
  620.         t2.millitm -= 1000;
  621.     }
  622.     for (;;) {
  623. #ifdef QUICKWIN
  624.         Py_BEGIN_ALLOW_THREADS
  625.         _wyield();
  626.         Py_END_ALLOW_THREADS
  627. #endif
  628.         if (PyErr_CheckSignals())
  629.             return -1;
  630.         ftime(&t1);
  631.         if (t1.time > t2.time ||
  632.             t1.time == t2.time && t1.millitm >= t2.millitm)
  633.             break;
  634.     }
  635. #else /* !MSDOS */
  636. #ifdef MS_WIN32
  637.     /* XXX Can't interrupt this sleep */
  638.     Py_BEGIN_ALLOW_THREADS
  639.     Sleep((int)(secs*1000));
  640.     Py_END_ALLOW_THREADS
  641. #else /* !MS_WIN32 */
  642. #ifdef PYOS_OS2
  643.     /* This Sleep *IS* Interruptable by Exceptions */
  644.     Py_BEGIN_ALLOW_THREADS
  645.     if (DosSleep(secs * 1000) != NO_ERROR) {
  646.         Py_BLOCK_THREADS
  647.         PyErr_SetFromErrno(PyExc_IOError);
  648.         return -1;
  649.     }
  650.     Py_END_ALLOW_THREADS
  651. #else /* !PYOS_OS2 */
  652. #ifdef _AMIGA
  653.     /* XXX Can't interrupt this sleep */
  654.     Py_BEGIN_ALLOW_THREADS
  655.     Delay((long)(secs*50));
  656.     Py_END_ALLOW_THREADS
  657. #else /* !_AMIGA */
  658.     /* XXX Can't interrupt this sleep */
  659.     Py_BEGIN_ALLOW_THREADS
  660.     sleep((int)secs);
  661.     Py_END_ALLOW_THREADS
  662. #endif /* !_AMIGA */
  663. #endif /* !PYOS_OS2 */
  664. #endif /* !MS_WIN32 */
  665. #endif /* !MSDOS */
  666. #endif /* !__WATCOMC__ || __QNX__ */
  667. #endif /* !macintosh */
  668. #endif /* !HAVE_SELECT */
  669.     return 0;
  670. }
  671.